package com.huike.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huike.entity.Menu;
import com.huike.entity.Roles;
import com.huike.mapper.MenuMapper;
import com.huike.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huike.service.IRolesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lwen
 * @since 2019-12-28
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {
    @Autowired
    IRolesService rolesService;

    @Autowired
    IMenuService menuService;

    @Override
    public List<Menu> getUserMenuByUserId(String user_id) {
        List<Roles> roles = rolesService.getRolesByUserId(user_id);
        List<String> menu_ids = new ArrayList<>();
        for (Roles r:roles){
            menu_ids.add(r.getMenuId());
        }
        if (menu_ids.size()==0){
            return null;
        }
        QueryWrapper<Menu> menuQueryWrapper = new QueryWrapper<>();
        menuQueryWrapper.in("id",menu_ids);
        return baseMapper.selectList(menuQueryWrapper);
    }
}
